package com.shelpe.services.sinbad.service.simbaproxy;

import java.util.Date;
import java.util.List;

import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonFormat.Shape;

import lombok.Data;
import lombok.Getter;
import lombok.Setter;

@FeignClient(name = "${feign.simba.name}", url = "${feign.simba.url}")
@RequestMapping(value = "/simba")
public interface AdgroupClient {

	@RequestMapping(method = RequestMethod.GET, value = "/taobao.simba.adgroup.add")
	CreateAdgroupResponse createAdgroup(@RequestParam("nick") String nick, @RequestParam("campaign_id") long campaignID,
			@RequestParam("item_id") long productID, @RequestParam("default_price") int defaultPrice,
			@RequestParam("title") String title, @RequestParam("img_url") String imageUrl);
	@Getter
	@Setter
	public static class CreateAdgroupResponse extends SimbaProxyBaseDto {
		@JsonProperty("simba_adgroup_add_response")
		private CreateAdgroupRes res;
	}

	@Data
	public static class CreateAdgroupRes {
		private AdgroupDto adgroup;
	}

	@Data
	public static class AdgroupDto {
		private String nick;
		@JsonProperty("adgroup_id")
		private long adgroupID;
		@JsonProperty("campaign_id")
		private long campaignID;
		@JsonProperty("category_ids")
		private String categoryIDs;

		@JsonProperty("num_iid")
		private long productID;
		@JsonProperty("product_name")
		private String productName;

		@JsonProperty("is_nonsearch_default_price")
		private boolean nonsearch;
		@JsonProperty("default_price")
		private int defaultPrice;
		@JsonProperty("nonsearch_max_price")
		private int nonsearchMaxPrice;

		@JsonProperty("online_status")
		private String onlineStatus;
		@JsonProperty("offline_type")
		private String offlineType;
		@JsonProperty("creative_title")
		private String creativeName;
		@JsonProperty("creative_img_url")
		private String creativeImgUrl;
		private String reason;
		
		@JsonProperty("modified_time")
		@JsonFormat(shape = Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
		private Date modifiedTime;
		@JsonProperty("create_time")
		@JsonFormat(shape = Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
		private Date createTime;
	}

	@RequestMapping(method = RequestMethod.GET, value = "/taobao.simba.creative.add")
	CreateCreativeResponse createCreatives(@RequestParam("nick") String nick, @RequestParam("adgroup_id") long adgroupID,
			@RequestParam("title") String creativeTitle, @RequestParam("img_url") String creativeImgUrl);

	@Getter
	@Setter
	public static class CreateCreativeResponse extends SimbaProxyBaseDto {
		@JsonProperty("simba_creative_add_response")
		private CreateCreativeRes res;
	}

	@Data
	public static class CreateCreativeRes {
		@JsonProperty("creative")
		private CreativeDto creative;
	}

	@Data
	public static class CreativeDto {
		private String nick;
		@JsonProperty("creative_id")
		private long creativeID;
		@JsonProperty("adgroup_id")
		private long adgroupID;
		@JsonProperty("campaign_id")
		private long campaignID;

		@JsonProperty("img_url")
		private String image;
		private String title;

		@JsonProperty("audit_status")
		private String auditStatus;
		@JsonProperty("audit_desc")
		private String auditDesc;

		@JsonProperty("modified_time")
		@JsonFormat(shape = Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
		private Date modifiedTime;
		@JsonProperty("create_time")
		@JsonFormat(shape = Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
		private Date createTime;
	}

	@RequestMapping(method = RequestMethod.GET, value = "/taobao.simba.creatives.get")
	GetCreativeResponse findCreatives(@RequestParam("nick") String nick, @RequestParam("adgroup_id") long adgroupID);

	@Getter
	@Setter
	public static class GetCreativeResponse extends SimbaProxyBaseDto{
		@JsonProperty("simba_creatives_get_response")
		private GetCreativeRes res;
	}

	@Data
	public static class GetCreativeRes {
		@JsonProperty("creatives")
		private CreativeDtos dataList;
	}

	@Data
	public static class CreativeDtos {
		@JsonProperty("creative")
		private List<CreativeDto> creatives;
	}
}